class TagController < ApplicationController 
  before_filter :verify_session,:index
  def index
    @tags= Book.tag_counts
  end
  
  def list
    @tags_pages, @tags_ = paginate :tags, :per_page => 10
  end
  
  def destroy
    tag_to_del = Tag.find(params[:id])
    taggings = tag_to_del.taggings
    taggings.destroy_all
    tag_to_del.destroy
    redirect_to :action => 'list'
  end
  
  def edit
    @tag_to_edit = Tag.find(params[:id])
  end
  
  def update
    tag =  Tag.find(params[:id])
    if tag.update_attributes(params[:tag_to_edit])
      flash[:info]="保存成功!"
      redirect_to :action => 'list'
      else
      flash[:info]="保存失败!"
      redirect_to :action => 'edit'
    end
  end
  
  def search
    tag_name = params['tag_name']
    @tags_ = Tag.find(:all,:conditions => ["name like ?",'%'+tag_name+'%'])
    @tags_pages = Paginator.new self, @tags_.size, 10, params[:page]
    render :action=>'list'
  end
  

end
